﻿using Benlai.Model.Common;
using Benlai.Dac.Common;
using Benlai.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Benlai.Bll.Common
{
    public class TreeManager
    {
        private static Dictionary<int, List<TreeModel>> dic = new Dictionary<int, List<TreeModel>>();

        public TreeManager()
        {

        }

        public List<List<TreeModel>> GetList(int type, int level)
        {
            TreeDac dac = new TreeDac();
            dac.SortPropertyName = "no";
            List<List<TreeModel>> list1 = new List<List<TreeModel>>();
            for (int i = level; i <= 10; i++)
            {
                var list = dac.GetList(i, type);
                if (list != null && list.Count > 0)
                {
                    list1.Add(list);
                }
                else
                {
                    break;
                }
            }
            return list1;
        }

        public List<List<TreeModel>> GetList()
        {
            TreeDac dac = new TreeDac();
            dac.SortPropertyName = "no";
            List<List<TreeModel>> list1 = new List<List<TreeModel>>();
            for (int i = 1; i <= 10; i++)
            {
                var list = dac.GetList(i);
                if (list != null && list.Count > 0)
                {
                    list1.Add(list);
                }
                else
                {
                    break;
                }
            }
            return list1;
        }

        public TreeModel Get(string no)
        {
            TreeDac dac = new TreeDac();
            dac.SortPropertyName = "no";
            var list = dac.Get(no);
            if (list == null || list.Count <= 0)
                return null;
            return list[0];
        }

        public void Save(TreeModel model)
        {
            TreeDac dac = new TreeDac();
            var m = dac.Get(model.no);
            if (m != null && m.Count > 0)
                model.Id = m[0].Id;

            dac.Set(model);
        }
    }
}
